import api from '@/api/index'
import { debtServer } from '@/utils/apiConfig'
const detailArr = ['/enterpriseDebt/', '/enterpriseDebtReturnApplication/', '/enterpriseInterestPrincipal/']
const approveArr = [
  '/enterpriseDebt/approveBatch',
  '/enterpriseDebtReturnApplication/list/approve:pass',
  '',
  '/corporationUserApplication/approveBatch'
]
const getRejectUrl = (type: number, id: string) => {
  if (type == 1) {
    return `/enterpriseDebt/${id}:reject`
  } else if (type == 4) {
    return `/corporationUserApplication/${id}:reject`
  } else {
    return `/enterpriseDebtReturnApplication/${id}/approve:reject`
  }
}
// 分页查询信息
export const getTabList = <T>(data?: unknown) => {
  return api.get<T>(debtServer + '/enterpriseDebt', data)
}
// 分页查询集团信息
export const getTabLastList = <T>(data?: unknown) => {
  return api.get<T>(debtServer + '/enterpriseDebt/corporationDebtStatistic', data)
}
// 获取详情
export const getMsgDetailById = <T>(id: string, type: number) => {
  return api.get<T>(debtServer + detailArr[type - 1] + id)
}
// 审核通过
export const approveApi = <T>(type: number, data?: unknown) => {
  return api.put<T>(debtServer + approveArr[type - 1], data)
}
// 审核拒绝
export const rejectApi = <T>(id: string, type: number, data?: unknown) => {
  return api.put<T>(debtServer + getRejectUrl(type, id), data)
}
// 查询字典
export const dictionary = <T>() => {
  return api.get(debtServer + '/dictionary?dictionaryCode=110')
}
